<?php

namespace app\v1\controller;
use support\Request;
use app\model\BannerModel;
use app\model\Util;
use app\model\AnnModel;
use app\model\MenuModel;

class CommonController {
    

    public function banners(Request $request){
        $data = BannerModel::whereNull('deleted_at')->where('type','=','index')->orderBy('sort_by','desc')->get();
        foreach($data as $item){
            $item->image = Util::pathToUrl($item->image);
        }

        $ann = AnnModel::orderBy('created_at', 'desc')
        ->select(['id', 'ann_title', 'created_at'])
        ->limit(3)->get();

        $menu = MenuModel::orderBy('created_at', 'desc')
        ->select(['id', 'name', 'path','image'])
        ->get();
        foreach($menu as $item){
            $item->image = Util::pathToUrl($item->image);
        }

        return json([
            'code' => 1,
            'data' => [
                'banners' => $data,
                'ann' => $ann,
                'menu' => $menu
            ],
        ]);
    }

    
}
